const state = {
    visible: false, // 弹窗是否显示
    componentName: '', // 弹窗组件名称
    data: null // 弹窗需要的额外数据
};

const mutations = {
    // 打开弹窗
    OPEN_POPUP(state, { componentName, data }) {
        state.visible = true;
        state.componentName = componentName;
        state.data = data || null;
    },
    // 关闭弹窗
    CLOSE_POPUP(state) {
        state.visible = false;
        state.componentName = '';
        state.data = null;
    }
};

const actions = {
    // 打开弹窗（供组件调用）
    openPopup({ commit }, payload) {
        commit('OPEN_POPUP', payload);
    },
    // 关闭弹窗（供组件调用）
    closePopup({ commit }) {
        commit('CLOSE_POPUP');
    }
};

export default {
    namespaced: true, // 开启命名空间，避免模块间冲突
    state,
    mutations,
    actions
};
